package com.youka.bussiness.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youka.bussiness.common.utils.BaseUtil;
import com.youka.bussiness.dao.entity.Orders;
import com.youka.bussiness.service.OrdersService;
import com.youka.bussiness.service.req.OrdersReqDto;
import com.youka.bussiness.service.req.OrdersUpdateDto;
import com.youka.bussiness.service.req.OrdersPageDto;
import com.youka.bussiness.service.res.OrdersDto;;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.youka.bussiness.common.bean.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import com.youka.bussiness.dao.OrdersMapper;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 订单信息表 Service 实现类
 *
 * @author lfc
 * @date 2024-06-30 16:47:28
 */
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {

    @Resource
    private OrdersMapper ordersMapper;

    /**
     * 查询详情
     *
     * @param id 查询参数
     * @return ordersDto
     */
    @Override
    public OrdersDto selectById(long id) {
        OrdersDto ordersDto = new OrdersDto();
        Orders orders = ordersMapper.selectById(id);
        if (orders != null){
            BeanUtils.copyProperties(orders,ordersDto);
        }
        return ordersDto;
    }

    /**
     * 集合查询订单信息表
     *
     * @param dto 查询参数
     * @return Page
     */
    @Override
    public List<OrdersDto> selectByList(OrdersReqDto dto) {
        LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper();
        List<Orders> Orderss = ordersMapper.selectList(wrapper);
        return BaseUtil.listToList(Orderss, OrdersDto.class);
    }

    /**
     * 分页查询订单信息表
     *
     * @param dto 查询参数
     * @return Page
     */
    @Override
    public IPage selectByPage(OrdersPageDto dto) {
        QueryWrapper<Orders> wrapper = Page.getPageWrapper(dto);
        return Page.copyProperties(this.page(Page.defaultPage(dto.getPageIndex(), dto.getPageSize()), wrapper)
                ,OrdersDto.class);
    }

    /**
     * 新增订单信息表
     *
     * @param dto 订单信息表
     * @return 新增结果
     */
    @Override
    public void insert(OrdersReqDto dto) {
        Orders orders = new Orders();
        BeanUtils.copyProperties(dto,orders);
        ordersMapper.insert(orders);
    }

    /**
       * 统计
        * @param dto
       * @return
       */
    @Override
     public  OrdersDto selectCount(OrdersReqDto dto){
        OrdersDto resp = new OrdersDto();
        ordersMapper.selectCount(new LambdaQueryWrapper<Orders>());
        return resp;
    }

    /**
     * 更新订单信息表
     * (根据主键)
     *
     * @param dto 订单信息表
     * @return 更新结果
     */
    @Override
    public void update(OrdersUpdateDto dto) {
        Orders orders =new Orders();
        BeanUtils.copyProperties(dto,orders);
        ordersMapper.updateById(orders);
    }

    /**
     * 删除订单信息表
     * (根据主键)
     *
     * @param orderId orderId
     * @return 删除结果
     */
    @Override
    public void deleteById(Integer orderId) {
        ordersMapper.deleteById(orderId);
    }


}
